import Vue from 'vue'
import Router from 'vue-router'
// import store from '@/store'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/employee',
    children: [{
      path: 'employee',
      name: '员工管理',
      component: () => import('@/views/employee/index'),
      meta: { role: ['admin'], title: '员工管理', icon: 'dashboard' }
    }, {
      path: 'employee/alert',
      name: 'addname',
      component: () => import('@/views/employee/alert'),
      hidden: true,
      meta: {
        activeMenu: '/employee'
      }
    }
    ]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { role: ['admin'], title: '', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/table/index'),
        meta: { role: ['admin'], title: '分类管理', icon: 'table' }
      }
    ]
  },

  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { role: ['admin'], title: '菜品管理', icon: 'form' }
      },
      {
        path: 'index/formlist',
        name: 'formlist',
        component: () => import('@/views/form/formlist'),
        meta: [{ title: '新增菜品' }, { title: '修改菜品' }],
        hidden: true
      }
    ]
  },

  {
    path: '/nested',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Nested',
    children: [
      {
        path: 'menu1',
        component: () => import('@/views/nested/menu1/index'), // Parent router-view
        name: 'Menu1',
        meta: { role: ['admin', 'super_editor'],
          title: '套餐管理',
          icon: 'nested'
        }
      },
      {
        path: 'menu1/formlist',
        name: 'formlist',
        component: () => import('@/views/nested/menu1/formlist'),
        meta: [{ title: '新增菜品' }],
        hidden: true
      }
    ]
  },
  {
    path: 'nested',
    component: Layout,
    children: [
      {
        component: () => import('@/views/nested/menu1/index'),
        path: 'menu1',
        meta: { role: ['admin', 'super_editor'], title: '订单明细', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
